package operation;

import book.Book;
import book.BookList;

import java.sql.SQLOutput;
import java.util.Scanner;

public class DelOperation implements  IOperation{
    public void work(BookList booklist){
        System.out.println("删除图书");
        int currentSize= booklist.getUsedSize();
        if(currentSize==0){
            System.out.println("书架为空，不能删除!");
            return;
        }
        Scanner scanner =new Scanner(System.in);
        System.out.println("请输入要删除的书名:");
        String name =scanner.nextLine();
        int index=-1;

        for (int i = 0; i <currentSize ; i++) {
            Book book1=booklist.getBook(i);
            if(book1.getName().equals(name)){
                index=i;
                break;

            }

        }
        if(index==-1){
            System.out.println("未找到你要删除的书");
            return;
        }
        for (int i = index; i <currentSize-1 ; i++) {
            Book book1=booklist.getBook(i+1);
            booklist.setBooks(i,book1);

        }
        booklist.setUsedSize(currentSize-1);


    }
}
